﻿namespace Tomato.Allure
{
	internal class ProjectImpl : Tomato.Allure.IProject
	{
		private EnvDTE.Project m_instance;

		public Tomato.Allure.IProjectItems ProjectItems
		{
			get 
			{
				if( m_instance.ProjectItems != null )
				{
					return new ProjectItemsImpl( m_instance.ProjectItems );
				}

				return null;
			}
		}

		public string Name
		{
			get { return m_instance.Name; }
		}

		public bool IsSaved
		{
			get { return m_instance.Saved; }
		}

		public ProjectImpl( EnvDTE.Project instance )
		{
			m_instance = instance;
		}

		public string FileName
		{
			get { return m_instance.FileName; }
		}

		public string FullName
		{
			get { return m_instance.FullName; }
		}

		public bool IsDirty
		{
			get { return m_instance.IsDirty; }
		}

		public Tomato.Allure.ProjectKind Kind
		{
			get
			{
				if( m_instance.Kind.Equals( "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}" ) )
				{
					return ProjectKind.CPlusPlusProject;
				}
				else if( m_instance.Kind.Equals( "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" ) )
				{
					return ProjectKind.CSharpProject;
				}
				else if( m_instance.Kind.Equals( "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}" ) )
				{
					return ProjectKind.VirtualFolder;
				}
				else if( m_instance.Kind.Equals( "{66A2671D-8FB5-11D2-AA7E-00C04F688DDE}" ) )
				{
					return ProjectKind.Misc;
				}
				else
				{
					return ProjectKind.Unknown;
				}
			}
		}

		public Tomato.Allure.IProjectItem ParentProjectItem
		{
			get
			{
				if( m_instance.ParentProjectItem != null )
				{
					return new ProjectItemImpl( m_instance.ParentProjectItem );
				}

				return null;
			}
		}

		public void Delete()
		{
			m_instance.Delete();
		}

		public void Save( string filePath )
		{
			m_instance.Save( filePath );
		}

		public void SaveAs( string newFilePath )
		{
			m_instance.SaveAs( newFilePath );
		}

		public object GetInstance()
		{
			return m_instance;
		}
	}
}